<?php
/**
 * Created by PhpStorm.
 * User: yzr
 * Date: 1/25/2021
 * Time: 23:33
 */
namespace app\api\controller\wap;

use mall\utils\Tool;
use think\facade\Db;
use think\facade\Request;
use app\common\model\users\WalletDetail as WalletDetailModel;

class WalletDetail extends Base
{
    /**
     * 流水日志
     */
    public function myList()
    {
        try {
            $limit = Request::get("limit");
            $where = [
                ['user_id','=',\mall\basic\Users::get('id')],
            ];
            if(!empty(Request::get('type'))){
                $where[]=['wallet_detail.type','=',Request::get('type')];
            }
            if(!empty(Request::get('create_time'))){
                [$start_time,$end_time]=explode('~',Request::get('create_time'));
                $where[]=['wallet_detail.create_time','>=',strtotime($start_time)];
                $where[]=['wallet_detail.create_time','<=',strtotime($end_time)];
            }
            $walletDetail = new WalletDetailModel();
            $list = $walletDetail->getList($where,$limit);
        } catch (\Exception $e) {
            return $this->returnAjax(Tool::getErrorMessage($e),0);
        }
        return $this->returnAjax("ok",1,$list['data'] ?? []);
    }

    public function typeList()
    {
        try {
            $data=[];
            $list= WalletDetailModel::getTypeList();
            foreach ($list as $key => $value) {
                $data[]=[
                    'type'=>$key,
                    'name'=>$value,
                ];
            }
        } catch (\Exception $e) {
            return $this->returnAjax(Tool::getErrorMessage($e),0);
        }
        return $this->returnAjax("ok",1,$data);
    }
}
